package com.woniu.airent.utils;

/**
 * description:
 *
 * @author AlenHx
 * @create 2020/9/28
 * @since 1.0.0
 */
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

import java.io.*;


public class JsonTest {

    //读取json文件
    public static String readJsonFile(String fileName) {
        String jsonStr = "";
        try {
            File jsonFile = new File(fileName);
            FileReader fileReader = new FileReader(jsonFile);
            Reader reader = new InputStreamReader(new FileInputStream(jsonFile),"utf-8");
            int ch = 0;
            StringBuffer sb = new StringBuffer();
            while ((ch = reader.read()) != -1) {
                sb.append((char) ch);
            }
            fileReader.close();
            reader.close();
            jsonStr = sb.toString();
            return jsonStr;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }


    public static void main(String[] args) {
        String path = JsonTest.class.getClassLoader().getResource("city.json").getPath();
        String s = readJsonFile(path);
        JSONArray jsonArray = JSON.parseArray(s);
        System.out.println(jsonArray);
    }
}